<?php
header("Content-type:text/html; charset=utf-8");
include('/var/www/html/new/d/module/api/function.class.php');
include('/var/www/html/new/d/module/api/PiaoLian/PiaoLian.class.php');

if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je");
	$le=new go_sql();
	$le->connect();
}

$PFT_infunction = new AllFunction();
$merchnum=14;
$txt2=file_get_contents('php://input');

/* $txt2 ='<?xml version="1.0" encoding="UTF-8"?><req><interfaceVersion>1.0.0.0</interfaceVersion><merchantNo>FXTEST</merchantNo><reqSerialNo>2861</reqSerialNo><reqTime>2015-11-17 16:09:10</reqTime><merVar></merVar><tranData>PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiID8+PHRyYW5EYXRhPjxwbGF0T3JkZXJObz4xNTEwMDkxNDM2PC9wbGF0T3JkZXJObz48bWVyY2hhbnRPcmRlck5PPnBmdDE0NDc3MzkzMTg2ODYwNDM5MTwvbWVyY2hhbnRPcmRlck5PPjxub3RpZnlEYXRhSUQ+Mjg2MTwvbm90aWZ5RGF0YUlEPjxlZGl0TW9kZT4xPC9lZGl0TW9kZT48cHJvZHVjdENvZGU+U1AwMDAwMDQ8L3Byb2R1Y3RDb2RlPjxwcm9kdWN0TnVtPjI8L3Byb2R1Y3ROdW0+PHByb2R1Y3RGYWN0TnVtPjI8L3Byb2R1Y3RGYWN0TnVtPjx0aWNrZXROdW1iZXI+5omL5bel5qC46ZSAPC90aWNrZXROdW1iZXI+PC90cmFuRGF0YT4=</tranData><signData>015050136e598e22bb18d61b4b235adf</signData></req>'; */

$data1= simplexml_load_string($txt2);
$reqTime = (string)$data1->reqTime;
$signData = (string)$data1->signData;
$tranData = base64_decode((string)$data1->tranData);

$tranData1 = simplexml_load_string($tranData);
$logdata= $txt2;
$func_res = 'checkNote';
$PFT_infunction->logfile("$merchnum|".$tranData1,$func_res);

$platOrderNo = (string)$tranData1->platOrderNo;			//票联订单号
$merchantOrderNO = (string)$tranData1->merchantOrderNO; //票付通临时订单号
$editMode  = (int)$tranData1->editMode; 				//1线下取票 2按票号退订 3商品使用 16整单退订
$productCode = (string)$tranData1->productCode; 		//商品编码
$productNum = (int)$tranData1->productNum ; 			//数量 

if(!$platOrderNo) exit;

$selapiOrder = "select pftOrder,tempOrder from all_api_order where apiOrder='$platOrderNo' limit 1";
$GLOBALS['le']->query($selapiOrder);
if(!$GLOBALS['le']->fetch_assoc())	exit("101");

$tempOrder = $GLOBALS['le']->f('tempOrder');
$pftOrder = $GLOBALS['le']->f('pftOrder');

$pft_order_xml = $PFT_infunction->Select_PFTorder($pftOrder);
$tid = (int)$pft_order_xml->Rec->UUtid;
$UUaids=	(string)$pft_order_xml->Rec->UUaids;
if($UUaids == 0){
	$UUaid = (int)$pft_order_xml->Rec->UUaid;
}else{
	$UUaidss= explode(',',$UUaids);
	$UUaid = $UUaidss[0];
}

$pl = new PiaoLian($UUaid);

if($platOrderNo && ($editMode == 1 || $editMode == 3 || $editMode == 8) ){
	$UUstatus =(int)$pft_order_xml->Rec->UUstatus;
	$UUtnum =(int)$pft_order_xml->Rec->UUtnum;
	$UUsalerid =(string)$pft_order_xml->Rec->UUsalerid;
	$UUcode = (string)$pft_order_xml->Rec->UUcode;
	$chkIns = 499;
	if((string)$pft_order_xml->Rec->UUstatus==2) $chkIns = 498;
	
	if($merchantOrderNO == $tempOrder){
		$r = $PFT_infunction->Unified_Check_IN($UUsalerid,$UUcode,date('Y-m-d H:i:s'),$chkIns);

		if($r == 100){
			$selorder = "update all_api_order set oStatus=1 where pftOrder='$pftOrder' limit 1";
			$GLOBALS['le']->query($selorder);
			$repCode = 1;
			$repMsg = '成功';
            $func_res = "check_s";
		}
		else{
			$repCode = 0;
			$repMsg = Err_Word($r);
            $func_res = "check_f";
		}
	}
	else{
		$repCode = 0;
		$repMsg = '不满足验证条件，验证失败';
        $r = $repMsg;
        $func_res = "check_f";
	}
    $logdata= $pftOrder."|".$platOrderNo."|".$r;
    $PFT_infunction->logfile("$merchnum|".$logdata,$func_res);
}
else{
	$repCode = 0;
	$repMsg = '无此订单';		
}
if($repMsg){
	$tranData='<?xml version="1.0" encoding="UTF-8" ?><notifyData><repCode>'.$repCode.'</repCode><repMsg>'.$repMsg.'</repMsg></notifyData>';
	$request = $pl->ass_post($tranData);
    $logdata= $repMsg."|".$request;
    $func_res = 'check_response';
    $PFT_infunction->logfile("$merchnum|".$logdata,$func_res);
	echo $request;
	exit;
}

function Err_Word($r){
	$errCode = array(
		'105'=>'找不到订单',
		'121'=>'订单状态出错,订单已验证',
		'119'=>'订单状态出错,已取消或其他状态',
		'521'=>'验证间隔时间未到',
		'133'=>'游玩时间未到',
		'134'=>'游玩时间已过',
		'118'=>'终端服务器无响应',
		'1070'=>'订单未支付',
	);
	$eword=$errCode[$r];
	if (!$eword) $eword='其他错误';
	return $eword;
}
?>